home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / opengl / colorChooser / chooser_sample.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  6.1 KB  |  222 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <string.h>        
  18. #include <stdio.h>
  19. #include <Xm/Xm.h>
  20. #include <stdlib.h>
  21. #include <Xm/PushB.h>
  22. #include <Xm/MenuShell.h>
  23. #include <Xm/CascadeB.h>
  24. #include <Xm/RowColumn.h>
  25. #include <Xm/MainW.h>
  26. #include <Xm/Form.h>
  27. #include <Xm/DialogS.h>
  28. #include <Xm/XmStrDefs.h>
  29. #include <X11/Shell.h>
  30. #include <Xm/MwmUtil.h>
  31. #include "includes/ColorC.h"
  32.  
  33. Widget Mainwin;     /* Main window widget - parent to all */
  34. Widget myDialog;    /* dialog widget for color chooser    */
  35.  
  36.  
  37. /* 
  38. **
  39. **    Call back for menu item 1 on Action menu
  40. **
  41. */
  42. void pbutton1_action(Widget w, XtPointer arg_int, XmAnyCallbackStruct *call_data)
  43. {
  44.     printf("Pushbutton 1 was selected\n");
  45. }
  46.  
  47.  
  48. /* 
  49. **
  50. **    Call back for quit button on menu bar
  51. **
  52. */
  53. void quit_action(Widget w, XtPointer arg_int, XmAnyCallbackStruct *call_data)
  54. {
  55.     exit(0);
  56. }
  57.  
  58. /* 
  59. **
  60. **    Create the popup dialog for the color chooser
  61. **     widget.
  62. **
  63. */
  64. void create_myDialog()
  65. {
  66.    Widget colorchooser;
  67.  
  68.    myDialog = XtVaCreatePopupShell( "eventList",
  69.               xmDialogShellWidgetClass, Mainwin,
  70.               XmNtitle, "ColorChooser Sample",
  71.               XmNminHeight, 400,
  72.           XmNminWidth, 500,
  73.               XmNallowShellResize, TRUE,
  74.               NULL );
  75.  
  76.     XtVaSetValues(myDialog, XmNx, 500, XmNy, 500, NULL);
  77.  
  78.     colorchooser = XtVaCreateManagedWidget("colorchooser",
  79.         sgColorChooserWidgetClass, myDialog,
  80.         NULL);
  81. }
  82.  
  83. /* 
  84. **
  85. **    Call back for menu item 1 on Action menu - invoke chooser
  86. **
  87. */
  88. void pbutton2_action(Widget w, XtPointer arg_int, XmAnyCallbackStruct *call_data)
  89. {
  90.     void create_myDialog();
  91.  
  92.     /* When invoked, create a new color chooser popup */
  93.     create_myDialog();
  94. }
  95.  
  96. /*
  97. **
  98. **  main
  99. **
  100. */
  101. main(argc, argv)
  102. int argc;
  103. char *argv[];
  104. {
  105.     Arg args[10];
  106.     int argcnt=0;
  107.     Widget button;
  108.     Widget pulldown;
  109.     Widget menubar;
  110.     Widget pbutton1, pbutton2;
  111.     Widget quit;
  112.     Window root;
  113.     void pbutton1_action();
  114.     void pbutton2_action();
  115.     void quit_action();
  116.     Widget pulldownshell;
  117.     XEvent queue_event;
  118.     XtAppContext appContext;
  119.     int screen;        
  120.     Display *dpy;            
  121.     Widget TopLevel;        
  122.    
  123.  
  124.         /* Initialize the Xt toolkit */
  125.         XtToolkitInitialize();
  126.  
  127.         /* Create an application context */
  128.         appContext = XtCreateApplicationContext();
  129.  
  130.         /* Open a display */
  131.         dpy = XtOpenDisplay(appContext, NULL, NULL, "Test", NULL ,0, &argc, (String *)argv);
  132.  
  133.         /* get the screen id 'screen */
  134.         screen = DefaultScreen(dpy);
  135.  
  136.         /* get the root window 'root' */
  137.         root = RootWindow(dpy, screen);
  138.  
  139.         /* Create the top level application shell */
  140.         TopLevel = XtAppCreateShell(NULL, "Color Chooser Test", applicationShellWidgetClass, dpy, args, 0);
  141.  
  142.         XSync(dpy, TRUE);
  143.  
  144.         /* Create the main window widget */
  145.     Mainwin = XtVaCreateManagedWidget( "x1", xmMainWindowWidgetClass,
  146.             TopLevel, XmNwidth, 300, XmNheight, 100, 
  147.             XmNresizePolicy, XmRESIZE_NONE, NULL);
  148.  
  149.         /* Create a menu bar */
  150.     menubar = XtVaCreateManagedWidget( "menubar", xmRowColumnWidgetClass,
  151.             Mainwin, 
  152.             XmNrowColumnType, XmMENU_BAR,
  153.             XmNwidth, 1000, XmNheight, 60, NULL);
  154.  
  155.         /* create the pulldown shell for the menu */
  156.     pulldownshell = XtVaCreateWidget("pulldownshell", 
  157.                         xmMenuShellWidgetClass, Mainwin,
  158.                         XmNwidth, 1,
  159.                         XmNheight, 1,
  160.                         XmNallowShellResize, TRUE,
  161.                         XmNoverrideRedirect, TRUE,
  162.                         NULL );
  163.  
  164.         /* Create the rowColumn for the menu */
  165.     pulldown = XtVaCreateWidget( "m1", xmRowColumnWidgetClass,
  166.         pulldownshell, 
  167.         XmNrowColumnType, XmMENU_PULLDOWN,
  168.         XmNheight, 60, NULL);
  169.  
  170.  
  171.         /* Create the cascade button for the menu bar */
  172.     button = XtVaCreateManagedWidget( "Actions", xmCascadeButtonWidgetClass, 
  173.             menubar,
  174.             XmNsubMenuId, pulldown, 
  175.             NULL);
  176.  
  177.         /* Add a quit button to the menu bar */
  178.     quit = XtVaCreateManagedWidget( "Quit", xmCascadeButtonWidgetClass, 
  179.         menubar,
  180.                 XmNlabelString, 
  181.                 (XmString *) XmStringCreate("Quit", XmFONTLIST_DEFAULT_TAG), 
  182.                 NULL);
  183.  
  184.         /* Callback for the quit button */
  185.     XtAddCallback(quit, XmNactivateCallback, quit_action, NULL);
  186.  
  187.         /* Add item 1 on the menu */
  188.     pbutton1 = XtVaCreateManagedWidget("selection 1", 
  189.         xmPushButtonWidgetClass, pulldown,
  190.         XmNaccelerator, "Ctrl<Key>n",
  191.         XmNacceleratorText,
  192.                 (XmString *) XmStringCreate("Ctrl+N", XmFONTLIST_DEFAULT_TAG),
  193.                 XmNlabelString,
  194.                 (XmString *) XmStringCreate("Prints Test Text", XmFONTLIST_DEFAULT_TAG),
  195.                 NULL);
  196.  
  197.         /* Callback for the first menu item */
  198.     XtAddCallback(pbutton1, XmNactivateCallback, pbutton1_action, NULL);
  199.  
  200.         /* Add item 2 on the menu, invoke color chooser */
  201.     pbutton2 = XtVaCreateManagedWidget("selection 2", 
  202.         xmPushButtonWidgetClass, pulldown,
  203.         XmNaccelerator, "Ctrl<Key>m",
  204.         XmNacceleratorText,
  205.                 (XmString *) XmStringCreate("Ctrl+M", XmFONTLIST_DEFAULT_TAG),
  206.                 XmNlabelString,
  207.                 (XmString *) XmStringCreate("Color Chooser", XmFONTLIST_DEFAULT_TAG),
  208.                 NULL);
  209.  
  210.         /* Callback for the second menu item, invoke color chooser */
  211.     XtAddCallback(pbutton2, XmNactivateCallback, pbutton2_action, NULL);
  212.  
  213.         /* Realize the top level widget */
  214.         XtRealizeWidget(TopLevel);
  215.  
  216.         /* Main loop */
  217.     while(True) {
  218.         XtAppNextEvent(appContext, &queue_event);
  219.         XtDispatchEvent(&queue_event);
  220.     }
  221. }
  222.